package com.dhwl.hsh.driver.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.dhwl.hsh.driver.R;

import java.util.List;

/**
 * popupwindow listview adapter
 *
 * @author Derek.Kidd
 * @version V1.0.0
 * @date 2016-05-05 16:31
 */
public class ListPopupWindowAdapter extends BaseAdapter<String> {

    private int checkPosition = -1;

    public ListPopupWindowAdapter(Context context, List<String> list) {
        super(context, list);
    }

    public int getCheckPosition() {
        return checkPosition;
    }

    public void setCheckPosition(int checkPosition) {
        this.checkPosition = checkPosition;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(context).inflate(R.layout.item_popupwindow_home, null);
        TextView textView = (TextView) convertView.findViewById(R.id.tv_pop_name);
        ImageView imageView = (ImageView) convertView.findViewById(R.id.img_pop_check);
        if (!TextUtils.isEmpty(getList().get(position)))
            textView.setText(getList().get(position));

        if (checkPosition == position) {
            textView.setTextColor(context.getResources().getColor(R.color.color_ff9b1a));
            imageView.setBackgroundResource(R.drawable.icon_home_pop_check);
        } else {
            textView.setTextColor(context.getResources().getColor(R.color.comm_tv_color));
            imageView.setBackgroundResource(R.drawable.selector_pop_check);
        }
        return convertView;
    }
}
